package com.firewolf.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("user")
public class UserHandler {
	
	@RequestMapping("login")
	public String login(@RequestParam("username") String uname,@RequestParam("pwd") String pwd){
		Subject subject = SecurityUtils.getSubject();
		if(!subject.isAuthenticated()){
			UsernamePasswordToken token = new UsernamePasswordToken(uname,pwd);
			try{
				token.setRememberMe(true);
				subject.login(token);
			}catch (AuthenticationException ae) {
				System.out.println("登录失败: " + ae.getMessage());
			}
		}

		return "redirect:/list.jsp";
	}
}
